//
//  FEGuideCell.m
//  familyeducation
//
//  Created by 聂志康 on 2017/3/24.
//  Copyright © 2017年 shangdingkeji. All rights reserved.
//

#import "FEGuideCell.h"
#import "HEBaseTabBarController.h"

@implementation FEGuideCell
#pragma mark - 添加按钮
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // MARK: - 立即体验按钮
        // 1.创建按钮
        UIButton *experienceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        // 默认隐藏！
        experienceBtn.hidden = YES;
        experienceBtn.backgroundColor = NAV_COLOR;
        [experienceBtn setTitle:@"进入应用" forState:UIControlStateNormal];
        // 3.添加
        [self.contentView addSubview:experienceBtn];
        
        // 4.调整大小
        if (kIPHONEX) {
            [experienceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.95);
                make.centerX.equalTo(self.contentView.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(kHeight(340/2), kHeight(80/2)));
            }];
        } else if (kIPHONE6P) {
            [experienceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.96);
                make.centerX.equalTo(self.contentView.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(kHeight(340/2), kHeight(80/2)));
            }];
        } else {
            [experienceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.97);
                make.centerX.equalTo(self.contentView.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(kHeight(340/2), kHeight(80/2)));
            }];
        }
        
        // 赋值
        _experienceBtn = experienceBtn;
        
        // 5.监听事件
        [experienceBtn addTarget:self action:@selector(experienceBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

#pragma mark - 进入主程序
- (void)experienceBtnClick {
    // 通过切换应用程序的主窗口的根控制器，进入主程序！
    [UIApplication sharedApplication].keyWindow.rootViewController = [[HEBaseTabBarController alloc] init];
}
@end
